<template>
    <div class="adBuyData shadow">
                 <el-form
          label-position="right" 
          label-width="130px" 
          :model="formdata"
          size="mini"
          style="width: 340px; margin-top:15px;"
          >
          <el-form-item :label="$t('adbuy.realname')">
           {{formdata.realName}}
          </el-form-item>
          <el-form-item label="HIGO ID" >
              {{formdata.erbanNo}}
          </el-form-item>
         <el-form-item :label="$t('login.log')+$t('login.name')">
           <span class="text">{{formdata.userName}}</span>&nbsp;&nbsp;&nbsp;&nbsp;<el-button @click="pwshow=true" type="text">{{$t('mallinfo.changpw')}}</el-button>
          </el-form-item>
          <el-form-item :label="$t('mallinfo.agentcoin')">
           {{formdata.coinBalance}}
          </el-form-item>
            <el-form-item :label="$t('mallinfo.total')+$t('mallinfo.agentcoin')">
            {{formdata.sumCoin}}
          </el-form-item>
           <el-form-item :label="$t('mallinfo.bankinfo')">
           <ul
               v-for="i in formdata.backList"
               :key="i.id"
           >
            <li>{{$t('adbuy.accountname')}}：{{i.accountName}}</li>
            <li>{{$t('adbuy.payaccount')}}：{{i.bankNumber}}</li>
            <li>{{$t('adbuy.paybank')}}SWIFT code：{{i.bankCode}}</li>
            <li>{{$t('adbuy.bankname')}}：{{i.bankName}}</li>
             <br/>
            </ul>

            
          </el-form-item>
        </el-form>
  <el-dialog :title="$t('mallinfo.changpw')"
  :visible.sync="pwshow"
  @close="hidepw"
  append-to-body
  top="25vh"
  >
  <el-form
  ref="form2"
  label-width="120px"
  :model="userpw"
  label-position="left"
  :rules="pwrule"
    >
  <el-form-item :label="$t('login.pw')" prop="input" >
     <el-input :placeholder="$t('login.pl')+$t('login.pw')" v-model="userpw.input"></el-input>
  </el-form-item>
  <el-form-item :label="$t('login.pl')+$t('login.pw')+$t('mallinfo.aga')" prop="check">
  <el-input :placeholder="$t('login.pl')+$t('login.pw')+$t('mallinfo.aga')" v-model="userpw.check"></el-input>
  </el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm('form2')"  class="confirm">{{$t('adbuy.confrim')}}</el-button>
</div>
</el-dialog>
        </div>
</template>

<script>
import { getAdminUser,getMallAccount ,resetPassword} from "../Util/request"
export default {
        data() {
                 var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error(this.$t('login.pl')+this.$t('login.pw')));
        } else {
          if (this.userpw.input !== '') {
            this.$refs.form2.validateField('check');
          }
          callback();
        }
      };
     var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error(this.$t('login.pl')+this.$t('login.pw')+this.$t('mallinfo.aga')));
        } else if (value !== this.userpw.input) {
          callback(new Error('error'));
        } else {
          callback();
        }
      };
            return {
                formdata:{
      
                },
                mallId:null,
                 pwrule:{
                  input:[{validator: validatePass, trigger: 'blur'}],
                  check:[{ validator: validatePass2, trigger: 'blur' }]
                },
                pwshow:false,
             userpw:{
                  input:"",
                  check:""
              },
            }
        },
        created(){
          
       getAdminUser((res)=>{
        this.mallId=res.data.mallId

            getMallAccount(res=>{
                this.formdata = res.data
            },{
                mallId:this.mallId
            })
      })
        },
        methods: {
        hidepw(){             
            this.pwshow=false
        },
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                 console.log(valid);
            if (valid) {
               
            //修改密码
                resetPassword(res=>{
                if(res.code==200){
                     this.$message({
                    message: this.$t('mallinfo.changsuc'),
                    type: 'success'
                });
                }else{
                    this.$message({
                    message: res.msg,
                    type: 'error'
                });
                }
                this.hidepw()
                },{
                    mallId:this.mallId,
                    newPassword:this.userpw.check,           
                  })
            } else {
               this.$message({
                 message: this.$t('mallinfo.check'),
                 type: 'warning'
               });
            return false;
          }
        });
      },
        },
}
</script>

<style>

</style>